package com.ysxsoft.wdg.adapter.order;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.cart.ShopcartBean;
import com.ysxsoft.wdg.util.ViewUtils;
import java.util.List;


public class ZyOrderInnerAdapter extends RecyclerView.Adapter<ZyOrderInnerAdapter.MyHolder> {

    private List<ShopcartBean> list;
    private Context mContext;
    private boolean isManJian = false;//是否是满减


    public ZyOrderInnerAdapter(List<ShopcartBean> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
    }

    public void setStatus(boolean isManJian) {
        this.isManJian = isManJian;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.include_order_goods,null); //解决条目显示不全
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_order_inner, parent,false);//解决宽度不能铺满
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        ShopcartBean item = list.get(position);
        Glide.with(mContext).load(item.getPic()).into(holder.ivGoods);
        holder.tvName.setText(item.getName());
        holder.tvNum.setText("x"+item.getNum());

        if(isManJian){
            holder.icon.setVisibility(View.GONE);
            holder.tvOldMoney.setTextColor(mContext.getResources().getColor(R.color.red_color));
            holder.tvOldMoney.setText("满"+item.getMan()+"减"+item.getJian());
            holder.tvMoney.setText(mContext.getString(R.string.price_rmb,item.getPrice()+""));
        }else{
            holder.icon.setVisibility(View.VISIBLE);
            ViewUtils.setDeletLine(holder.tvOldMoney);
            holder.tvOldMoney.setText(mContext.getString(R.string.price_rmb,item.getPrice()));
            holder.tvMoney.setText(mContext.getString(R.string.price_rmb,item.getL_price()+""));
        }
    }

    @Override
    public int getItemCount() {
        return list == null?0:list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder{

        private ImageView ivGoods;
        private TextView tvName,tvMoney,tvOldMoney,tvRules,tvJf,tvNum;
        private ImageView icon;
        public MyHolder(View itemView) {
            super(itemView);

            ivGoods= itemView.findViewById(R.id.iv_pic);
            icon= itemView.findViewById(R.id.icon);
            tvName = itemView.findViewById(R.id.tv_name);
            tvMoney = itemView.findViewById(R.id.tv_money);
            tvOldMoney = itemView.findViewById(R.id.tv_old_money);
            tvRules = itemView.findViewById(R.id.tv_rules);
            tvJf = itemView.findViewById(R.id.tv_jf);
            tvNum = itemView.findViewById(R.id.tv_num);
        }
    }
}
